<?php

namespace Database\Seeders;

use App\Models\Permission;
use App\Models\Role;
use Illuminate\Database\Seeder;

class RoleSeeder extends Seeder
{
  /**
   * Run the database seeds.
   */
  public function run()
  {
    // Admin
    $adminPerms = Permission::all();
    $admin = new Role();
    $admin->slug = 'admin';
    $admin->name = 'Administrator';
    $admin->save();
    $admin->permissions()->attach($adminPerms);
    // Editor
    $editorPerms = Permission::where('slug', 'LIKE', '%read-%')
      ->orWhere('slug', 'LIKE', '%manage-%')
      ->get();
    $user = new Role();
    $user->slug = 'editor';
    $user->name = 'Editor';
    $user->save();
    $user->permissions()->attach($editorPerms);
    // Reader
    $readerPerms = Permission::where('slug', 'LIKE', '%read-%')
      ->get();
    $reader = new Role();
    $reader->slug = 'reader';
    $reader->name = 'Reader';
    $reader->save();
    $reader->permissions()->attach($readerPerms);
  }
}
